<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>用CSS设置宽高的后果</title>
  <style>
    #c {
      width: 400px;
      height: 400px;
      border: 1px solid #ccc;
    }
  </style>
</head>
<body>
  <canvas id="c"></canvas>

  <script>
    // 1、获取canvas对象
    const context = document.getElementById('c')

    // 2、获取canvas上下文环境对象
    const ctx = context.getContext('2d')

    // 3、绘制图形
    ctx.moveTo(100, 100) // 起点
    ctx.lineTo(200, 100) // 终点
    ctx.stroke() // 将起点和终点连接起来

    console.log(context.width)
    console.log(context.height)
  </script>
</body>
</html>